/**
 * 产品修改js
 */
var comValidform = null;
var returnStatus = false;
var productInfoUpdateStatus = {
	dataCache : null,
	key:null,
	proStatus:null,
	hotSale:null,
	startEvent : function() {
		productInfoUpdateStatus.showInfo();

		//只有当设置为上架时才能设置热销
		$('select[name="proStatus"]').change(function() {
			var proStatus = $(this).val();
			productInfoUpdateStatus.proStatus = proStatus;
			if ( proStatus == "1") {
				$('#txTr').css('display', '');
			} else {
				$('#txTr').css('display', 'none');
				$('select[name="hotSale"]').val(0);
			}
		});
		
		
		$('select[name="hotSale"]').change(function() {
			var hotSale = $(this).val();
			productInfoUpdateStatus.hotSale = hotSale;
		});
		
		comValidform = $(".com-addForm").Validform({
			datatype : {
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype : 2,
			tipSweep : true,
			beforeSubmit : function(curform) {
				var id = $('input[name="id"]').val(); 
				var proStatus = productInfoUpdateStatus.proStatus;
				var hotSale =  productInfoUpdateStatus.hotSale;
				var url = 'mgr/ProductInfoCtrl/updateStatus';
				var params ={
			   		'id':id,
				    'proStatus': proStatus,
				    'hotSale':hotSale
						
				};
				var cb = function(data) {
					alert(data.msg);
					// 成功返回
					if (data.resultCode == 200) {
						localStorage.removeItem(productInfoUpdateStatus.key);
						// 关闭窗口并刷新数据
						art.dialog.close();
						returnStatus = true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},

	showInfo: function() {
	 
		var id = art.dialog.data('updId');
		productInfoUpdateStatus.key = id + "_ProductType03_Key";
		var ret = eval('(' + localStorage.getItem(productInfoUpdateStatus.key) + ')');
		$('input[name="name"]').val(ret.name);
		$('input[name="id"]').val(ret.id);
		$('select[name="hotSale"]').val(ret.hotSale);
		$('select[name="proStatus"]').val(ret.proStatus);
		productInfoUpdateStatus.proStatus = ret.proStatus;
		productInfoUpdateStatus.hotSale = ret.hotSale;
	},
	init : function() {
		productInfoUpdateStatus.startEvent();
	}
}
$(document).ready(function() {
	productInfoUpdateStatus.init();
});
function submitForm() {
	comValidform.submitForm();
	return returnStatus;
}